import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: uni.getStorageSync('state') ? JSON.parse(uni.getStorageSync('state')) : {
		forcedLogin: false,
		hasLogin: false,
		token: "",
		user: {},
		modelId: 0, //房型ld
		indexPageData: {},
		audioSwith:true,//语音通知
		showPage:0,
	},
	mutations: {
		login(state, user) {
			state.token = user.token || null;
			state.user = user;
			state.hasLogin = true;
			uni.setStorageSync("token", user.token);
			uni.setStorageSync('user',user);
		},
		logout(state) {
			state.token = "";
			state.user = {};
			state.hasLogin = false;
			uni.removeStorageSync("token");
			uni.removeStorageSync("user");
			uni.reLaunch({
				url: '/pages/login/login'
			});
		},
		changeModel(state, id) {
			state.modelId = id;
		},
		indexData(state,obj){
			state.indexPageData=obj
		},
		changeAudio(state,obj){
			state.audioSwith=obj
			console.log(state.audioSwith,"state.audioSwith")
		},
		changeShowPage(state,obj){
			console.log("obj",obj)
			state.showPage=obj;
		}
	},
	  actions:{
	        changeShowPageF:function(context,mData){
				console.log(mData,"mData")
	            context.commit('changeShowPage',mData)
	        },
	    }
})

export default store